"""
测试MySQL操作
"""
from pymysql import Connection

# 创建数据库连接
conn = Connection(
    host="localhost",
    port=3306,
    user="root",
    passwd="Gqyj158569.#",
)

# 打印服务器信息
print(conn.get_server_info())

# 获取游标对象
cursor = conn.cursor()

# 选择库
conn.select_db("sun_mall")

# 执行语句
#cursor.execute("create table user(id int, name varchar(20), password varchar(20))")

cursor.execute("select * from user")

result = cursor.fetchall()
for row in result:
    print(row)

# 用完关闭数据库
conn.close()